package com.ps.actions.person;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.ps.actions.BaseAction;
import com.ps.global.Globals;
import com.ps.pojo.person.Employee;
import com.ps.service.person.EmployeeService;

public class LoginAction extends BaseAction {
    @Autowired
	private EmployeeService employeeService;
	private Employee employee;
	private String message = "";
	
	
	private static final String MAIN = "main";
	
	
	/**
	 * 用户登录
	 * @return
	 */
	public String login() {

		
		if (employee == null) {
			return LOGIN;
		} 
		if (StringUtils.isEmpty(request.getHeader("referer"))) {
			return LOGIN;
		}
		if (StringUtils.isBlank(employee.getUserName())) {
			message = "用户名不能为空";
			return LOGIN;
		}
		if (StringUtils.isBlank(employee.getPassword())) {
			message = "密码不能为空";
			return LOGIN;
		}

		Employee user =  employeeService.login(employee.getUserName(), employee.getPassword());
		
		if (user != null) {

			getSession().put(Globals.SESSION_USER, user);
			return MAIN;
		}
		message = "您的账户或密码不正确,请重新输入!";
		return LOGIN;
	}


	public Employee getEmployee() {
		return employee;
	}


	public void setEmployee(Employee employee) {
		this.employee = employee;
	}


	public String getMessage() {
		return message;
	}


	public void setMessage(String message) {
		this.message = message;
	}
}
